package com.czy.owner.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.czy.owner.R;
import com.czy.owner.entity.HomeServiceModel;
import com.czy.owner.entity.ShoppingModel;
import com.czy.owner.utils.glide.GlideUtils;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;


/**
 * Created by asus on 2017/5/9.
 */
public class HomeSecKillAdapter extends RecyclerArrayAdapter<ShoppingModel.GoodsActivityBean.ActivitySecondsKillBean> {

    public HomeSecKillAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new HomeSecKillHolder(parent);
    }

    class HomeSecKillHolder extends BaseViewHolder<ShoppingModel.GoodsActivityBean.ActivitySecondsKillBean> {
        private ImageView ivGoodsImg;
        private TextView tvGoodsOriginal;
        private TextView tvGoodsSale;
        private TextView tvProductName;

        public HomeSecKillHolder(ViewGroup parent) {
            super(parent, R.layout.item_shopping_seckill);
            tvProductName = $(R.id.tv_product_name);
            ivGoodsImg = $(R.id.iv_goods_img);
            tvGoodsOriginal = $(R.id.tv_goods_original);
            tvGoodsSale = $(R.id.tv_goods_sale);
        }

        @Override
        public void setData(ShoppingModel.GoodsActivityBean.ActivitySecondsKillBean model) {
            super.setData(model);
            tvProductName.setText(model.getGoodsName());
            tvGoodsOriginal.setText("￥"+String.format("%.2f",model.getGoodsSpecValuesPrice()));
            tvGoodsSale.setText("￥"+String.format("%.2f",model.getKillPrice()));
            tvGoodsOriginal.getPaint().setAntiAlias(true);
            tvGoodsOriginal.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
            GlideUtils.loadImage(getContext(), model.getLogo(), ivGoodsImg, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
                @Override
                public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {

                }

                @Override
                public void onLoadingError(String source, Exception e) {

                }
            },R.mipmap.default_icon,R.mipmap.default_icon);

        }
    }
}

